<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商家店铺列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>商铺分类：</label>
                            <select name="shopTypeId" id="shopTypeId" th:with="list=${@dict.selectShopTypeList()}">
                                <option value="">所有</option>
                                <option th:each="shopType : ${list}" th:text="${shopType.typeName}"
                                        th:value="${shopType.id}"></option>
                            </select>
                        </li>
                        <li>
                            <label>单位名称：</label>
                            <input type="text" name="shopCompany"/>
                        </li>
                        <li>
                            <label>商铺区域：</label>
                            <input type="text" id="treeName" onclick="selectCityTree()"/>
                            <input type="text" name="shopCityId" id="shopCityId" hidden/>
                        </li>
                        <input type="text" name="isValid" value="1" hidden/>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="toMySearch()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="msgToAllShop()" > <i class="fa fa-adjust"></i> 全部发放
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('WxShop:WxShop:edit')}]];
    var removeFlag = [[${@permission.hasPermi('WxShop:WxShop:remove')}]];
    var msgId = [[${msgId}]];

    var prefix = ctx + "WxShop/WxShop";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            rememberSelected: true,
            modalName: "商家店铺",
            columns: [{
                field: 'state',
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'null',
                    visible: false
                },
                {
                    field: 'shopName',
                    title: '商铺名称'
                },
                {
                    field: 'shopCompany',
                    title: '单位名称'
                },
                {
                    field: 'shopTel',
                    title: '管理员电话'
                },
                {
                    field: 'discountRatio',
                    title: '让利比'
                },
                {
                    field: 'typeName',
                    title: '商铺分类',
                },
                {
                    field: 'cityName',
                    title: '地区',
                },
                {
                    field: 'shopAdress',
                    title: '店铺地址'
                }]
        };
        $.table.init(options);
    });



    function selectCityTree() {
        var url = ctx + "WxCitys/WxCitys/selectCitysTree/" + 100;
        var options = {
            title: '选择城市',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#shopCityId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);

    }

    function submitHandler() {
        var arrays = $.table.selectColumns("id").toString();
        $.modal.confirm("是否确认发送消息到商家", function () {
            $.post(ctx + "wxMessage/wxMessage/msgToShop", {
                msgId: msgId,
                wids: arrays
            }, function (result) {
                $.operate.saveSuccess(result);
            })
        })
    }

    /*搜索*/
    var data={}
    function toMySearch() {
        data={};
        data.shopTypeId = $("#shopTypeId").val()
        data.shopCompany = $("input[name='shopCompany']").val()
        data.shopCityId = $("input[name='shopCityId']").val()
        console.log(data)
        $.table.search()
    }

    /*全部放发*/
    function msgToAllShop() {
        $.modal.confirm("是否确认发送消息给当前所有店铺", function () {
            data.msgId =msgId;
            $.post(ctx + "wxMessage/wxMessage/msgToAllShop", data, function (result) {
                $.operate.saveSuccess(result);
            })
        })
    }

</script>
</body>
</html>